package Bidostar_Page;

import Bidostar_BaseData.Page;
import Bidostar_Data.Baseinfo;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

import java.util.concurrent.TimeUnit;

public class PrivilegePage extends Page
{
    public PrivilegePage(WebDriver driver)
    {
        super(driver);
    }

    public void clickprivilemanage()
    {
        getElement("privilemanage").click();
    }

    public void clickAdd_privile()
    {
        getElement("Add_privile").click();
    }

    public void Input_PrivileGroupName(String Input_PrivileGroupName)
    {
        getElement("Input_PrivileGroupName").clear();
        getElement("Input_PrivileGroupName").sendKeys(Input_PrivileGroupName);
    }

    public void clickis_Select()
    {
        getElement("is_Select").click();
    }

    public void clickSelect_Privile_SG()
    {
        getElement("Select_Privile_SG").click();
    }

    public void clickCar_JK()
    {
        getElement("Car_JK").click();
    }

    public void clickAlert_Sure()
    {
        getElement("Alert_Sure").click();
    }

    public void clickPrivile_GroupSave()
    {
        getElement("Privile_GroupSave").click();
    }

    public boolean PrivilegeAdd()
    {
        try
        {
            if (driver.getCurrentUrl().contains("dc.bidostar.com"))
            {
                logger.warn("调度平台暂无权限组管理!");
            } else
            {
                clickprivilemanage();
                clickAdd_privile();
                Input_PrivileGroupName(Baseinfo.PrivileGroupName);
                if (Baseinfo.PrivileGroupName.length() <= 0)
                {
                    clickPrivile_GroupSave();
                    logger.info(getElement("FeedBack_Alert").getText());
                    clickAlert_Sure();
                    logger.info(getElement("Alert_Sure").getText());
                    logger.warn(getElement("PrivileGroupName_ErrorMessage").getText());
                } else
                {
                    clickis_Select();
                    clickSelect_Privile_SG();
                    clickPrivile_GroupSave();
                    logger.info(getElement("FeedBack_Alert").getText());
                    clickAlert_Sure();
                    logger.info(getElement("Alert_Sure").getText());
                    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
                    logger.info("弹窗提示：" + getElement("FeedBack_Alert").getText() + Baseinfo.PrivileGroupName);
                    clickAlert_Sure();
                    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
                    if (driver.findElement(By.xpath(".//*[@id='tab-list']/div/div/table/tbody/tr[1]/td[1]")).getText().equals(Baseinfo.PrivileGroupName))
                    {
                        logger.info("权限组添加成功：" + driver.findElement(By.xpath(".//*[@id='tab-list']/div/div/table/tbody/tr[1]/td[1]")).getText());
                    } else
                    {
                        logger.warn("列表中第一列与新添加不符");
                    }
                }
            }
        } catch (Exception e)
        {
            e.printStackTrace();
            logger.warn("运行异常");
        }

        return false;
    }

}
